package com.seh.contentcenter.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.seh.contentcenter.dto.CommentDTO;
import com.seh.contentcenter.dto.ReplyDTO;
import com.seh.contentcenter.entity.Comment;
import com.seh.contentcenter.entity.Reply;
import com.seh.contentcenter.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private CommentService commentService;


    /**
     * 获取所有帖子，并分页查询
     *
     * @param postId
     * @param currentPage
     * @return
     */
    @GetMapping("/findAllComment")
    public CommentDTO getAllComments(@RequestParam("postId") Integer postId,
                                     @RequestParam("currentPage") Integer currentPage) {
        CommentDTO allComments = commentService.getAllComments(postId, currentPage);
        return allComments;
    }

    @GetMapping("/findCommentById")
    public CommentDTO getCommentById(@RequestParam("id") Integer id,
                                     @RequestParam("currentPage") Integer currentPage) {
        return commentService.getCommentById(id, currentPage);
    }

    /**
     * 新增评论--回复帖子
     *
     * @param username
     * @param content
     * @return
     */
    @GetMapping("/insertCommentAboutPost")
    public String insertCommentAboutPost(@RequestParam("postId") Integer postId,
                                         @RequestParam("username") String username,
                                         @RequestParam("content") String content,
                                         @RequestParam("userId") Integer userId) {
        return commentService.insertCommentAboutPost(postId, username, content, userId);

    }
}
